package com.bzgwl.cloud_sys.controller;

import com.bzgwl.cloud_sys.entity.UserDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Professor_Kong
 * @version 1.0
 * @date 2020/3/2 15:02
 */

@RestController
public class MainController {

    @RequestMapping("/a")
    @PreAuthorize("hasAnyAuthority('p1')")
    public String a(){
        //获取用户身份信息
        UserDTO userDTO = (UserDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return userDTO.getUsername()+"  访问A资源！！ 需要 ：p1 权限";
    }

    @RequestMapping("/b")
    @PreAuthorize("hasAnyAuthority('p3')")
    public String b(){

        //获取用户身份信息
        UserDTO userDTO = (UserDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return userDTO.getUsername()+ "  访问A资源！！ 需要：p3  权限";
    }
}
